package zdream.pmfield.stage.buff.foe;

import java.util.Objects;
import java.util.function.Function;

import zdream.pmfield.data.foe.MoveCheckPair;
import zdream.pmfield.stage.effect.AbstractEffect;
import zdream.pmfield.stage.effect.Effects;
import zdream.pmfield.stage.director.HookStore;
import zdream.pmfield.stage.director.HookType;
import zdream.pmfield.stage.object.StageMove;

/**
 * 一个临时性的 buff, 在技能发动前添加, 在技能发送后删除.
 * 这类 buff 的改变不会触发 {@link zdream.pmfield.stage.message.FoeAddBuffMessage} 和
 * {@link zdream.pmfield.stage.message.FoeRemoveBuffMessage}
 *
 * @author Zdream
 * @date 2023-11-27
 * @since 0.0.1
 */
public class MoveExecutingBuff extends FoeStageBuff {
	public static final String CATEGORY = "moveExecuting";
	public final StageMove move;

	public MoveExecutingBuff(StageMove move) {
		super(move.foe);
		this.move = move;
	}

	@Override
	public void init() {
		// nothing
	}

	public void putHooksWithMoveEffect(MoveCheckPair pair) {
		Objects.requireNonNull(pair);

		if (pair.additions == null && move.additions == null) {
			return;
		}

		final Effects effects = target.stage.director.effects;
		// 技能的效果都优先触发
		Function<HookType, HookStore.HookHandlerBuilder> onHook = type -> this.onHook(type).withPriority(-100);

		if (move.additions != null) {
			for (String addition : move.additions) {
				final AbstractEffect effect = effects.createEffect(addition);
				effect.init(onHook);
			}
		}
		if (pair.additions != null) {
			for (String addition : pair.additions) {
				final AbstractEffect effect = effects.createEffect(addition);
				effect.init(onHook);
			}
		}
	}

	@Override
	public String getCategory() {
		return CATEGORY;
	}

	@Override
	public String toString() {
		return "正在发动技能";
	}
}
